package com.qianya.oa.controller.activiti;

import com.github.pagehelper.PageInfo;
import com.qianya.oa.common.core.controller.BaseController;
import com.qianya.oa.domain.FormDef;
import com.qianya.oa.dto.FormParam;
import com.qianya.oa.dto.FormQueryParam;
import com.qianya.oa.dto.FormUpdateParam;
import com.qianya.oa.service.FormDefService;
import com.qianya.oa.util.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(value = "表单接口")
@RestController
@RequestMapping("/form/manage")
public class FormController extends BaseController {

    @Resource
    private FormDefService formDefService;

    /**
     * 查询表单列表
     */
    @PostMapping("/list")
    @ResponseBody
    public PageInfo<FormDef> list(FormQueryParam formQueryParam) {
        return formDefService.selectFormList(formQueryParam);
    }


    /**
     * 新增设计表单
     */
    @ApiOperation("新增设计表单")
    @PostMapping("/save")
    public CommonResult save(@RequestBody FormParam formParam) {
        String s = formDefService.save(formParam);
        if (s != null) {
            return CommonResult.erro(s);
        } else {
            return CommonResult.success();
        }
    }

    /**
     * 更改设计表单
     */
    @ApiOperation("更改设计表单")
    @PostMapping("/update")
    public CommonResult update(@RequestBody FormUpdateParam formUpdateParam) {
        String s = formDefService.update(formUpdateParam);
        if (s != null) {
            return CommonResult.erro(s);
        } else {
            return CommonResult.success();
        }
    }


}
